package com.hefei

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author caizhengjun
 * @date 2020/8/27 8:44 下午
 */
object RDDTest3 {

  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf().setMaster("local[2]").setAppName(this.getClass.getSimpleName)

    val sc: SparkContext = new SparkContext(conf)

    val strings: Array[String] = sc.parallelize(Seq("Hello lily", "Hello lucy", "Hello tim")).flatMap(_.split(" ")).collect()

    val tuples = strings.map((_, 1))

    val unit: RDD[(String, Int)] = sc.makeRDD(tuples).reduceByKey(_ + _)

    unit.collect().foreach(println(_))
  }

}
